package com.lanou.beautifulwardrobe.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;

import com.android.volley.Response;
import com.google.gson.Gson;
import com.lanou.beautifulwardrobe.Activity_zhuti.Adapter.IntroTListViewAdapter;
import com.lanou.beautifulwardrobe.Brand.Adapter.BrandListViewAdapter;
import com.lanou.beautifulwardrobe.Home.Adapter.IntroFRecyclerViewAdapter;
import com.lanou.beautifulwardrobe.R;
import com.lanou.beautifulwardrobe.contants.Contants;
import com.lanou.beautifulwardrobe.contants.VolleySingleton;
import com.lanou.beautifulwardrobe.entify.ChoiceProduct;
import com.lanou.beautifulwardrobe.entify.ChoiceResult;
import com.lanou.beautifulwardrobe.entify.IntroData;
import com.lanou.beautifulwardrobe.entify.IntroOutfit;
import com.lanou.beautifulwardrobe.entify.IntroResult;

import java.util.List;

/**
 * Created by dllo on 15/11/6.
 */
public class IntroTActivity extends Activity implements View.OnClickListener {
    private ListView introTLv;
    private String ids;
    private IntroData data;
    private ImageButton intrTBack;
    private TextView intrTTitle, introTDecription;
    private VolleySingleton volleySingleton = VolleySingleton.getInstance();
    private BrandListViewAdapter listViewAdapter;
    private IntroTListViewAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_introthree);
        this.ids = getIntent().getStringExtra("ids");
        this.data = (IntroData) getIntent().getSerializableExtra("data");
        initView();
        initData();
    }

    private void initView() {
        introTLv = (ListView) findViewById(R.id.introTLv);
        View header = View.inflate(this, R.layout.activity_introone_header, null);
        introTLv.addHeaderView(header);
        intrTBack = (ImageButton) findViewById(R.id.introTBack);
        intrTTitle = (TextView) findViewById(R.id.introTTitle);
        introTDecription = (TextView) header.findViewById(R.id.introODecription);
        listViewAdapter = new BrandListViewAdapter();
        adapter = new IntroTListViewAdapter();
        listener();
    }

    private void listener() {
        intrTBack.setOnClickListener(this);
    }

    private void initData() {

        intrTTitle.setText(data.getShort_title());
        introTDecription.setText(data.getDescription());

        introTLv.setAdapter(adapter);
        String url = Contants.INTRO_THREE_URL_PRODUCT_PREFIX + ids + Contants.INTRO_THREE_URL_PRODUCT_SUFFIX;
        Log.i("lanou", url + "///*");
        volleySingleton.getStringRequset(url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Gson gson = new Gson();
                IntroResult introResult = gson.fromJson(response, IntroResult.class);
                if (introResult != null) {
                    List<IntroOutfit> introOutfits = introResult.getData().getContent().getData().getOutfits();
                    adapter.addData(introOutfits);

                }
            }
        });
    }


    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.introTBack:
                finish();
                break;
        }

    }


}
